﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using NJL.IDAL;
using Royalsoft.DBUtility;//Please add references
namespace NJL.SQLServerDAL
{
	/// <summary>
	/// 数据访问类:NJL_AD
	/// </summary>
	public partial class NJL_AD:INJL_AD
	{
		public NJL_AD()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from NJL_AD");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(NJL.Model.NJL_AD model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into NJL_AD(");
			strSql.Append("ID,NJL_SYS_BASE_ID,NJL_CS_AD_SPACE_ID,AD_NAME,AD_START_DATE_TIME,AD_END_DATE_TIME,AD_CONTENT,PUBLISH_TO_WEBSITECODE,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME)");
			strSql.Append(" values (");
			strSql.Append("@ID,@NJL_SYS_BASE_ID,@NJL_CS_AD_SPACE_ID,@AD_NAME,@AD_START_DATE_TIME,@AD_END_DATE_TIME,@AD_CONTENT,@PUBLISH_TO_WEBSITECODE,@UPDATE_USER_NAME,@UPDATE_USER_ID,@UPDATE_DATE_TIME,@CREATE_USER_NAME,@CREATE_USER_ID,@CREATE_DATE_TIME)");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20),
					new SqlParameter("@NJL_SYS_BASE_ID", SqlDbType.VarChar,20),
					new SqlParameter("@NJL_CS_AD_SPACE_ID", SqlDbType.VarChar,20),
					new SqlParameter("@AD_NAME", SqlDbType.VarChar,100),
					new SqlParameter("@AD_START_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@AD_END_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@AD_CONTENT", SqlDbType.Text),
					new SqlParameter("@PUBLISH_TO_WEBSITECODE", SqlDbType.VarChar,1000),
					new SqlParameter("@UPDATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@UPDATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@UPDATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@CREATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@CREATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_DATE_TIME", SqlDbType.DateTime)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.NJL_SYS_BASE_ID;
			parameters[2].Value = model.NJL_CS_AD_SPACE_ID;
			parameters[3].Value = model.AD_NAME;
			parameters[4].Value = model.AD_START_DATE_TIME;
			parameters[5].Value = model.AD_END_DATE_TIME;
			parameters[6].Value = model.AD_CONTENT;
			parameters[7].Value = model.PUBLISH_TO_WEBSITECODE;
			parameters[8].Value = model.UPDATE_USER_NAME;
			parameters[9].Value = model.UPDATE_USER_ID;
			parameters[10].Value = model.UPDATE_DATE_TIME;
			parameters[11].Value = model.CREATE_USER_NAME;
			parameters[12].Value = model.CREATE_USER_ID;
			parameters[13].Value = model.CREATE_DATE_TIME;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(NJL.Model.NJL_AD model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update NJL_AD set ");
			strSql.Append("NJL_SYS_BASE_ID=@NJL_SYS_BASE_ID,");
			strSql.Append("NJL_CS_AD_SPACE_ID=@NJL_CS_AD_SPACE_ID,");
			strSql.Append("AD_NAME=@AD_NAME,");
			strSql.Append("AD_START_DATE_TIME=@AD_START_DATE_TIME,");
			strSql.Append("AD_END_DATE_TIME=@AD_END_DATE_TIME,");
			strSql.Append("AD_CONTENT=@AD_CONTENT,");
			strSql.Append("PUBLISH_TO_WEBSITECODE=@PUBLISH_TO_WEBSITECODE,");
			strSql.Append("UPDATE_USER_NAME=@UPDATE_USER_NAME,");
			strSql.Append("UPDATE_USER_ID=@UPDATE_USER_ID,");
			strSql.Append("UPDATE_DATE_TIME=@UPDATE_DATE_TIME,");
			strSql.Append("CREATE_USER_NAME=@CREATE_USER_NAME,");
			strSql.Append("CREATE_USER_ID=@CREATE_USER_ID,");
			strSql.Append("CREATE_DATE_TIME=@CREATE_DATE_TIME");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@NJL_SYS_BASE_ID", SqlDbType.VarChar,20),
					new SqlParameter("@NJL_CS_AD_SPACE_ID", SqlDbType.VarChar,20),
					new SqlParameter("@AD_NAME", SqlDbType.VarChar,100),
					new SqlParameter("@AD_START_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@AD_END_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@AD_CONTENT", SqlDbType.Text),
					new SqlParameter("@PUBLISH_TO_WEBSITECODE", SqlDbType.VarChar,1000),
					new SqlParameter("@UPDATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@UPDATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@UPDATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@CREATE_USER_NAME", SqlDbType.VarChar,50),
					new SqlParameter("@CREATE_USER_ID", SqlDbType.VarChar,20),
					new SqlParameter("@CREATE_DATE_TIME", SqlDbType.DateTime),
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = model.NJL_SYS_BASE_ID;
			parameters[1].Value = model.NJL_CS_AD_SPACE_ID;
			parameters[2].Value = model.AD_NAME;
			parameters[3].Value = model.AD_START_DATE_TIME;
			parameters[4].Value = model.AD_END_DATE_TIME;
			parameters[5].Value = model.AD_CONTENT;
			parameters[6].Value = model.PUBLISH_TO_WEBSITECODE;
			parameters[7].Value = model.UPDATE_USER_NAME;
			parameters[8].Value = model.UPDATE_USER_ID;
			parameters[9].Value = model.UPDATE_DATE_TIME;
			parameters[10].Value = model.CREATE_USER_NAME;
			parameters[11].Value = model.CREATE_USER_ID;
			parameters[12].Value = model.CREATE_DATE_TIME;
			parameters[13].Value = model.ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from NJL_AD ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from NJL_AD ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public NJL.Model.NJL_AD GetModel(string ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 ID,NJL_SYS_BASE_ID,NJL_CS_AD_SPACE_ID,AD_NAME,AD_START_DATE_TIME,AD_END_DATE_TIME,AD_CONTENT,PUBLISH_TO_WEBSITECODE,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME from NJL_AD ");
			strSql.Append(" where ID=@ID ");
			SqlParameter[] parameters = {
					new SqlParameter("@ID", SqlDbType.VarChar,20)};
			parameters[0].Value = ID;

			NJL.Model.NJL_AD model=new NJL.Model.NJL_AD();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["ID"]!=null && ds.Tables[0].Rows[0]["ID"].ToString()!="")
				{
					model.ID=ds.Tables[0].Rows[0]["ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"]!=null && ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"].ToString()!="")
				{
					model.NJL_SYS_BASE_ID=ds.Tables[0].Rows[0]["NJL_SYS_BASE_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NJL_CS_AD_SPACE_ID"]!=null && ds.Tables[0].Rows[0]["NJL_CS_AD_SPACE_ID"].ToString()!="")
				{
					model.NJL_CS_AD_SPACE_ID=ds.Tables[0].Rows[0]["NJL_CS_AD_SPACE_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["AD_NAME"]!=null && ds.Tables[0].Rows[0]["AD_NAME"].ToString()!="")
				{
					model.AD_NAME=ds.Tables[0].Rows[0]["AD_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["AD_START_DATE_TIME"]!=null && ds.Tables[0].Rows[0]["AD_START_DATE_TIME"].ToString()!="")
				{
					model.AD_START_DATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["AD_START_DATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["AD_END_DATE_TIME"]!=null && ds.Tables[0].Rows[0]["AD_END_DATE_TIME"].ToString()!="")
				{
					model.AD_END_DATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["AD_END_DATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["AD_CONTENT"]!=null && ds.Tables[0].Rows[0]["AD_CONTENT"].ToString()!="")
				{
					model.AD_CONTENT=ds.Tables[0].Rows[0]["AD_CONTENT"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PUBLISH_TO_WEBSITECODE"]!=null && ds.Tables[0].Rows[0]["PUBLISH_TO_WEBSITECODE"].ToString()!="")
				{
					model.PUBLISH_TO_WEBSITECODE=ds.Tables[0].Rows[0]["PUBLISH_TO_WEBSITECODE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_USER_NAME"]!=null && ds.Tables[0].Rows[0]["UPDATE_USER_NAME"].ToString()!="")
				{
					model.UPDATE_USER_NAME=ds.Tables[0].Rows[0]["UPDATE_USER_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_USER_ID"]!=null && ds.Tables[0].Rows[0]["UPDATE_USER_ID"].ToString()!="")
				{
					model.UPDATE_USER_ID=ds.Tables[0].Rows[0]["UPDATE_USER_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"]!=null && ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"].ToString()!="")
				{
					model.UPDATE_DATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["UPDATE_DATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CREATE_USER_NAME"]!=null && ds.Tables[0].Rows[0]["CREATE_USER_NAME"].ToString()!="")
				{
					model.CREATE_USER_NAME=ds.Tables[0].Rows[0]["CREATE_USER_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_USER_ID"]!=null && ds.Tables[0].Rows[0]["CREATE_USER_ID"].ToString()!="")
				{
					model.CREATE_USER_ID=ds.Tables[0].Rows[0]["CREATE_USER_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"]!=null && ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString()!="")
				{
					model.CREATE_DATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,NJL_SYS_BASE_ID,NJL_CS_AD_SPACE_ID,AD_NAME,AD_START_DATE_TIME,AD_END_DATE_TIME,AD_CONTENT,PUBLISH_TO_WEBSITECODE,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME ");
			strSql.Append(" FROM NJL_AD ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" ID,NJL_SYS_BASE_ID,NJL_CS_AD_SPACE_ID,AD_NAME,AD_START_DATE_TIME,AD_END_DATE_TIME,AD_CONTENT,PUBLISH_TO_WEBSITECODE,UPDATE_USER_NAME,UPDATE_USER_ID,UPDATE_DATE_TIME,CREATE_USER_NAME,CREATE_USER_ID,CREATE_DATE_TIME ");
			strSql.Append(" FROM NJL_AD ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "NJL_AD";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

